package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lxh.testinfo.R;

import java.util.List;
import java.util.Map;

/**
 * Created by Lxh on 2017/12/19.
 */

public class ListViewAdapter extends BaseAdapter {
    private List<Map<String, Object>> mData;
    private LayoutInflater mInflater;

    public ListViewAdapter(Context context, List<Map<String, Object>> mData) {
        this.mData = mData;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = mInflater.inflate(R.layout.itemlayout, null);
            holder.m_tv_number = view.findViewById(R.id.tv_number);
            holder.iv_mark = view.findViewById(R.id.iv_mark);
            holder.m_tv_plate = view.findViewById(R.id.tv_plate);
            holder.m_ch_batch = view.findViewById(R.id.cb_batch);
            holder.m_btn_recharge = view.findViewById(R.id.btn_recharge);
            holder.m_tv_money = view.findViewById(R.id.tv_money);
            holder.m_tv_name = view.findViewById(R.id.tv_name);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.m_tv_number.setText((String) mData.get(position).get("number"));
        holder.m_tv_name.setText((String) mData.get(position).get("name"));
        holder.m_tv_money.setText((String) mData.get(position).get("money"));
        holder.m_tv_plate.setText((String) mData.get(position).get("plate"));
        holder.m_btn_recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mIntemPayListener.OnPayClick(position);
            }
        });
        return view;
    }

    public interface OnItemPayListener {
        void OnPayClick(int i);
    }

    private OnItemPayListener mIntemPayListener;

    public void setOnItemPayClickListener(OnItemPayListener mIntemPayListener) {
        this.mIntemPayListener = mIntemPayListener;
    }


    class ViewHolder {
        public TextView m_tv_number;
        public ImageView iv_mark;
        public TextView m_tv_plate;
        public TextView m_tv_name;
        public TextView m_tv_money;
        public CheckBox m_ch_batch;
        public Button m_btn_recharge;
    }
}
